package com.wp.controller;

import com.wp.entity.User;
import com.wp.service.UserService;
import com.wp.vo.LoginVo;
import com.wp.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author: WangPeng
 * @createTime: 2022/11/22 14:29
 * @description:
 * @version: v1.0
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户表的增删改查")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("/list")
    @ApiOperation(value = "查询需所有用户")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前显示第几页",name = "current",dataType = "int",required = true,defaultValue = "1"),
            @ApiImplicitParam(value = "每页显示几条",name = "pageSize",dataType = "int",required = true,defaultValue = "5")})
    public Result list(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize){
        return userService.selectAll(currentPage,pageSize);
    }

    @PostMapping("/del")
    @ApiOperation(value = "根据用户id删除用户")
    @ApiImplicitParam(value = "部门id",name = "id",dataType = "int",defaultValue = "93",required = true)
    public Result del(int id){
        return userService.deleteById(id);
    }

    @PostMapping("/updateUser")
    @ApiOperation(value="修改用户信息")
    public Result updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @PostMapping("/insertUser")
    @ApiOperation(value = "添加用户")
    public Result insertUser(@RequestBody User user){
        return userService.insertUser(user);
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public Result login(@RequestBody LoginVo loginVo){
        return userService.login(loginVo);
    }

}
